var login_ops = {
    'init':function()
    {
        this.eventBind();
    },
    'eventBind':function()
    {
        $('#login-btn').on('click',function(){
            var form = $('#form1'),
                email = $('#email').val(),
                pass = $('#pass').val();
            if(!(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email)))
            {
                layer.alert('请输入正确邮箱号!');
                return false;
            }

            if(!pass)
            {
                layer.alert('请输入密码!');
                return false;
            }

            $.ajax({
                'type':'POST',
                'url':'/admin/login',
                'data':form.serialize(),
                'dataType':'json',
                'beforeSend':function(){
                    layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                },
                'success':function(data)
                {
                    layer.closeAll();
                    if(data.code != 200)
                    {
                        layer.alert(data.msg);
                        return false;
                    }
                    location.href = '/';
                }
            });
        });
    }
};

$(document).ready(function(){
    login_ops.init();
});